package com.kb.erp.entity.quote;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class ResponseDeJie {
    private int code;
    private String msg;
    private int count;
    private List<Item> data;

    // Getters and Setters
    public int getCode() { return code; }
    public void setCode(int code) { this.code = code; }
    public String getMsg() { return msg; }
    public void setMsg(String msg) { this.msg = msg; }
    public int getCount() { return count; }
    public void setCount(int count) { this.count = count; }
    public List<Item> getData() { return data; }
    public void setData(List<Item> data) { this.data = data; }
    @JsonIgnoreProperties(ignoreUnknown = true)
    public static  class Item {
        private String ven_partnumber;
        private String ven_mfc_mode;
        private String ven_brand;

        public String getVen_desc_dtl() {
            return ven_desc_dtl;
        }

        public void setVen_desc_dtl(String ven_desc_dtl) {
            this.ven_desc_dtl = ven_desc_dtl;
        }

        private String  ven_desc_dtl;

        public String getVen_package() {
            return ven_package;
        }

        public void setVen_package(String ven_package) {
            this.ven_package = ven_package;
        }

        private String ven_package;

        @JsonProperty("QuantityAvailable")
        private String QuantityAvailable;

        public Integer getMinimumOrderQuantity() {
            return MinimumOrderQuantity;
        }

        public void setMinimumOrderQuantity(Integer minimumOrderQuantity) {
            MinimumOrderQuantity = minimumOrderQuantity;
        }

        @JsonProperty("MinimumOrderQuantity")
        private Integer  MinimumOrderQuantity;

        @JsonProperty("MyPricing")
        private List<Pricing> MyPricing;

        @JsonProperty("StandardPricing")
        private List<Pricing> StandardPricing;

        // Getters and Setters
        public String getVen_partnumber() { return ven_partnumber; }
        public void setVen_partnumber(String ven_partnumber) { this.ven_partnumber = ven_partnumber; }

        public String getVen_mfc_mode() { return ven_mfc_mode; }
        public void setVen_mfc_mode(String ven_mfc_mode) { this.ven_mfc_mode = ven_mfc_mode; }

        public String getVen_brand() { return ven_brand; }
        public void setVen_brand(String ven_brand) { this.ven_brand = ven_brand; }

        public String getQuantityAvailable() { return QuantityAvailable; }
        public void setQuantityAvailable(String quantityAvailable) { this.QuantityAvailable = quantityAvailable; }

        public List<Pricing> getMyPricing() { return MyPricing; }
        public void setMyPricing(List<Pricing> myPricing) { this.MyPricing = myPricing; }

        public List<Pricing> getStandardPricing() { return StandardPricing; }
        public void setStandardPricing(List<Pricing> standardPricing) { this.StandardPricing = standardPricing; }

        public static   class Pricing {
            @JsonProperty("BreakQuantity")
            private int BreakQuantity;

            @JsonProperty("UnitPrice")
            private String UnitPrice;

            @JsonProperty("TotalPrice")
            private String TotalPrice;

            // Getters and Setters
            public int getBreakQuantity() { return BreakQuantity; }
            public void setBreakQuantity(int breakQuantity) { this.BreakQuantity = breakQuantity; }

            public String getUnitPrice() { return UnitPrice; }
            public void setUnitPrice(String unitPrice) { this.UnitPrice = unitPrice; }

            public String getTotalPrice() { return TotalPrice; }
            public void setTotalPrice(String totalPrice) { this.TotalPrice = totalPrice; }
        }

        public void sortPricingLists() {
            if (MyPricing != null) {
                MyPricing.sort(Comparator.comparingInt(Pricing::getBreakQuantity));
            }
            if (StandardPricing != null) {
                StandardPricing.sort(Comparator.comparingInt(Pricing::getBreakQuantity));
            }
        }

        //数量
        public String generatePriceString3() {
            StringBuilder sb = new StringBuilder();
            boolean isFirst = true;
            if (StandardPricing != null && !StandardPricing.isEmpty()) {
                for (Pricing standardPrice : StandardPricing) {
                    if (!isFirst) {
                        sb.append("<br/>");
                    }
                    sb.append(standardPrice.getBreakQuantity())

                    ;
                    isFirst = false;
                }
            }
            return sb.toString();
        }

        //标准价
        public String generatePriceString2() {
            StringBuilder sb = new StringBuilder();
            boolean isFirst = true;
            if (StandardPricing != null && !StandardPricing.isEmpty()) {
                for (Pricing standardPrice : StandardPricing) {
                    if (!isFirst) {
                        sb.append("<br/>");
                    }
                           sb .append(standardPrice.getUnitPrice())
                    ;
                    isFirst = false;
                }
            }

            return sb.toString();
        }





        //折扣价
        public String generatePriceString() {
            StringBuilder sb = new StringBuilder();
            boolean isFirst = true;

            if (StandardPricing != null && !StandardPricing.isEmpty()) {
                for (Pricing standardPrice : StandardPricing) {
                    if (!isFirst) {
                        sb.append("<br/>");
                    }

                    // Find matching MyPricing
                    Pricing myPrice = findMatchingPricing(MyPricing, standardPrice.getBreakQuantity());
                    String myPriceStr = (myPrice != null) ? myPrice.getUnitPrice() : "-";
                    sb
                            .append(myPriceStr)
                    ;

                    isFirst = false;
                }
            }

            return sb.toString();
        }

        private Pricing findMatchingPricing(List<Pricing> pricingList, int quantity) {
            if (pricingList != null && !pricingList.isEmpty()) {
                for (Pricing pricing : pricingList) {
                    if (pricing.getBreakQuantity() == quantity) {
                        return pricing;
                    }
                }
            }
            return null;
        }






    }



}
